package cn.csdj.sism.web;

import cn.csdj.sism.pojo.ObtainEmployment;
import cn.csdj.sism.service.ObtainEmploymentService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * @author 李加
 * 2023/4/10
 */
@CrossOrigin
@RestController
@RequestMapping("/obtainEmployment")
public class ObtainEmploymentController {
    @Autowired
    private ObtainEmploymentService obtainEmploymentService;

    /**
     * 通过id查询
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ObtainEmployment selectById(@PathVariable Integer id){
       return obtainEmploymentService.selectById(id);
    }
    /**
     * 查询全部
     * @return
     */
    @GetMapping
    public List<ObtainEmployment> selectAll(){
        return obtainEmploymentService.selectAll();
    }

    /**
     * 添加
     * @param obtainEmployment
     */
    @PostMapping
    public int insert(@RequestBody ObtainEmployment obtainEmployment){
        if (StringUtils.isEmpty(obtainEmployment.getObtainEmpId())){
            return obtainEmploymentService.insertOem(obtainEmployment);
        }else {
            return obtainEmploymentService.updateOem(obtainEmployment);
        }
    }

    /**
     * 修改
     * @param obtainEmployment
     */
    @PutMapping
    public int update(@RequestBody ObtainEmployment obtainEmployment){
        return obtainEmploymentService.updateOem(obtainEmployment);
    }

    /**
     * 删除
     * @param id
     */
    @DeleteMapping("/{id}")
    public int delect(@PathVariable Integer id){
        return obtainEmploymentService.dalectOemById(id);
    }

    /**
     * 分页查询
     * @param current
     * @param pageSize
     * @return
     */
    @GetMapping("/page/{current}/{pageSize}")
    public IPage<ObtainEmployment> selectByPage(@PathVariable Integer current, @PathVariable Integer pageSize){
        return obtainEmploymentService.selectByPage(current,pageSize);
    }

    /**
     * 按条件查询
     * @param condition
     * @return
     */
    @PostMapping("/condition")
    public IPage<ObtainEmployment> selectByCondition(@RequestBody HashMap condition){
        return obtainEmploymentService.selectPagesByCondition(condition);
    }
}
